package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.OrderClassRequestVO;
import com.yugong.entity.vo.response.OrderClassListResponseVO;
import com.yugong.service.OrderClassService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单班控制器类
 *
 * @author yugong
 * @date 2024/2/21
 */
@RestController
@RequestMapping("/api/order-class")
public class OrderClassController {
    @Resource
    private OrderClassService orderClassService;

    /**
     * 根据班名、订单班管理员工号查询订单班信息（未发布）
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 订单班信息
     */
    @GetMapping("/find-order-class-no-release-page")
    public Result findOrderClassNoReleasePage(@RequestParam(defaultValue = "1") Integer pageNum,
                                              @RequestParam(defaultValue = "5") Integer pageSize,
                                              @RequestParam String orderClassAdminNo,
                                              @RequestParam String orderClassName) {
        PageInfo<OrderClassListResponseVO> orderClassListVOPageInfo
                = orderClassService.findOrderClassNoReleasePage(pageNum, pageSize, orderClassAdminNo, orderClassName);
        return Result.success(orderClassListVOPageInfo);
    }

    /**
     * 根据班名、订单班管理员工号查询订单班信息（发布）
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 订单班信息
     */
    @GetMapping("/find-order-class-release-page")
    public Result findOrderClassReleasePage(@RequestParam(defaultValue = "1") Integer pageNum,
                                            @RequestParam(defaultValue = "5") Integer pageSize,
                                            @RequestParam String orderClassAdminNo,
                                            @RequestParam String orderClassName) {
        PageInfo<OrderClassListResponseVO> orderClassListVOPageInfo
                = orderClassService.findOrderClassReleasePage(pageNum, pageSize, orderClassAdminNo, orderClassName);
        return Result.success(orderClassListVOPageInfo);
    }

    /**
     * 根据班名、订单班管理员工号查询订单班信息（开班）
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 订单班信息
     */
    @GetMapping("/find-order-class-start-page")
    public Result findOrderClassStartReleasePage(@RequestParam(defaultValue = "1") Integer pageNum,
                                                 @RequestParam(defaultValue = "5") Integer pageSize,
                                                 @RequestParam String orderClassAdminNo,
                                                 @RequestParam String orderClassName) {
        PageInfo<OrderClassListResponseVO> orderClassListVOPageInfo
                = orderClassService.findOrderClassStartReleasePage(pageNum, pageSize, orderClassAdminNo, orderClassName);
        return Result.success(orderClassListVOPageInfo);
    }

    /**
     * 根据班名、订单班管理员工号查询订单班信息（所有）
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 订单班信息
     */
    @GetMapping("/find-order-class-page")
    public Result findOrderClassPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "5") Integer pageSize,
                                     @RequestParam String orderClassAdminNo,
                                     @RequestParam String orderClassName) {
        PageInfo<OrderClassListResponseVO> orderClassListVOPageInfo
                = orderClassService.findOrderClassPage(pageNum, pageSize, orderClassAdminNo, orderClassName);
        return Result.success(orderClassListVOPageInfo);
    }

    /**
     * 新增订单班
     *
     * @param orderClassRequestVO 订单班请求实体类
     * @return 响应码
     */
    @PostMapping("/add-order-class")
    public Result addOrderClass(@RequestBody OrderClassRequestVO orderClassRequestVO) {
        int addFlag = orderClassService.addOrderClass(orderClassRequestVO);
        return Result.success(addFlag);
    }

    /**
     * 修改订单班
     *
     * @param orderClassRequestVO 订单班请求实体类
     * @return 响应码
     */
    @PutMapping("/update-order-class")
    public Result updateOrderClass(@RequestBody OrderClassRequestVO orderClassRequestVO) {
        int updateFlag = orderClassService.updateOrderClass(orderClassRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 删除订单班
     *
     * @param orderClassNo 订单班号
     * @return 响应码
     */
    @DeleteMapping("/delete-order-class")
    public Result deleteOrderClass(@RequestParam String orderClassNo) {
        int deleteFlag = orderClassService.deleteOrderClass(orderClassNo);
        return Result.success(deleteFlag);
    }

    /**
     * 订单班 发布、开班、结班
     *
     * @param orderClassRequestVO 订单班请求实体类
     * @return 响应码
     */
    @PutMapping("/change-order-class")
    public Result changeOrderClass(@RequestBody OrderClassRequestVO orderClassRequestVO) {
        int changeFlag
                = orderClassService.changeOrderClassState(orderClassRequestVO.getOrderClassState(),
                orderClassRequestVO.getOrderClassNo(), orderClassRequestVO.getOrderClassAdministratorNo());
        return Result.success(changeFlag);
    }

    /**
     * 根据订单班管理员工号查询订单班
     *
     * @param orderClassAdminNo 订单班管理员工号
     * @return 订单班
     */
    @GetMapping("/find-order-class-order-class-admin-no/{orderClassAdminNo}")
    public Result findOrderClassByOrderClassAdminNo(@PathVariable String orderClassAdminNo) {
        List<OrderClassListResponseVO> orderClassListResponseVOList
                = orderClassService.findOrderClass(orderClassAdminNo);
        return Result.success(orderClassListResponseVOList);
    }

    /**
     * 根据班名查询订单班信息
     *
     * @param pageNum        当前页
     * @param pageSize       当前页数据个数
     * @param orderClassName 班名
     * @return 订单班信息
     */
    @GetMapping("/find-order-class-page-admin")
    public Result findOrderClassPageAdmin(@RequestParam(defaultValue = "1") Integer pageNum,
                                          @RequestParam(defaultValue = "5") Integer pageSize,
                                          @RequestParam String orderClassName) {
        PageInfo<OrderClassListResponseVO> orderClassListVOPageInfo
                = orderClassService.findOrderClass(pageNum, pageSize, orderClassName);
        return Result.success(orderClassListVOPageInfo);
    }

    /**
     * 根据班号查询订单班状态
     *
     * @param orderClassNo 班号
     * @return 订单班状态
     */
    @GetMapping("/find-order-class-state/{orderClassNo}")
    public Result findOrderClassState(@PathVariable String orderClassNo) {
        Integer orderClassState = orderClassService.findOrderClassState(orderClassNo);
        return Result.success(orderClassState);
    }

    /**
     * 查询学生可以报名的订单班
     *
     * @return 学生可以报名的订单班
     */
    @GetMapping("/search-order-class-student/{studentNo}")
    public Result searchOrderClassStudent(@RequestParam(defaultValue = "1") Integer pageNum,
                                          @RequestParam(defaultValue = "5") Integer pageSize,
                                          @RequestParam String orderClassName,
                                          @PathVariable String studentNo) {
        PageInfo<OrderClassListResponseVO> orderClassListResponseVOPageInfo
                = orderClassService.searchOrderClassStudent(pageNum, pageSize, orderClassName, studentNo);
        return Result.success(orderClassListResponseVOPageInfo);
    }

    /**
     * 查询未发布的订单班
     *
     * @param orderClassState   未发布的订单班
     * @param orderClassAdminNo 工号
     * @return 未发布的订单班
     */
    @GetMapping("/find-order-class/{orderClassState}/{orderClassAdminNo}")
    public Result findOrderClass(@PathVariable Integer orderClassState, @PathVariable String orderClassAdminNo) {
        List<OrderClassListResponseVO> orderClassListResponseVOList
                = orderClassService.findOrderClass(orderClassAdminNo, orderClassState);
        return Result.success(orderClassListResponseVOList);
    }
}
